package home.my.base.util;

import home.my.recordmanage.model.TableSeqs;
import home.my.recordmanage.util.GlobalParameters;

import org.hibernate.Session;

public class DataBaseUtil {
	
	//生成id方法
	public static Long generateId(Session session,String tableName){
    	long id = GlobalParameters.DEFAULT_BEGIN_ID;
    	TableSeqs oldSeq = (TableSeqs) session.load(TableSeqs.class, tableName);
    	if(oldSeq == null){  //正常情况下不会发生
    		oldSeq = new TableSeqs();
    		oldSeq.setTableName(tableName);
    		oldSeq.setTableId(id);
    		session.save(oldSeq);
    	}
    	else{
    		id = oldSeq.getTableId()+1;
    		oldSeq.setTableId(id);
    		session.update(oldSeq);
    	}
    	return id;
	}
}
